import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.brandId)
        requiredFields.push(
            formatMessage({
                id: 'validator.brandId',
                defaultMessage: '品牌'
            })
        );
    if(!data || !data.technologyActivityId)
        requiredFields.push(
            formatMessage({
                id: 'validator.technologyActivityId',
                defaultMessage: '技术升级'
            })
        );
    if(!data || !data.telephone)
        requiredFields.push(
            formatMessage({
                id: 'validator.telephone',
                defaultMessage: '电话'
            })
        );
    if(!data || !data.email)
        requiredFields.push(
            formatMessage({
                id: 'validator.email',
                defaultMessage: '电子邮件'
            })
        );
    if(!data || !data.delayReason)
        requiredFields.push(
            formatMessage({
                id: 'validator.delayReason',
                defaultMessage: '活动延期原因'
            })
        );
    if(!data || !data.deadlineTime)
        requiredFields.push(
            formatMessage({
                id: 'validator.deadlineTime',
                defaultMessage: '活动推迟截止时间'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    return true;
};
export const newOrApproveOrderValidator = data => {
    const requiredFields = [];
    if(!data || !data.delayReason)
        requiredFields.push(
            formatMessage({
                id: 'validator.delayReason',
                defaultMessage: '活动延期原因'
            })
        );
    if(!data || !data.recommendedFullRate)
        requiredFields.push(
            formatMessage({
                id: 'validator.recommendedFullRate',
                defaultMessage: '活动延迟的建议完全比率'
            })
        );
    if(!data || !data.deadlineTime)
        requiredFields.push(
            formatMessage({
                id: 'validator.deadlineTime',
                defaultMessage: '活动推迟截止时间'
            })
        );
    if(!data || !data.approveComment)
        requiredFields.push(
            formatMessage({
                id: 'validator.approveComment',
                defaultMessage: '审核意见'
            })
        );
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.requied',
            defaultMessage: '必填'
        })}`);
        return false;
    }
    if(!data || data.isError) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.confirmComment',
            defaultMessage: '多级审核配置不正确!'
        })}`);
        return false;
    }
    return true;
};
